//
// Created by liuyang on 2025/5/16.
//

#include "ManagerController.h"

void ManagerController::showOptions() {
    cout<<"欢迎来到管理员后台管理系统"<<endl;
    cout<<"****1.添加账号****"<<endl;
    cout<<"****2.查看账号****"<<endl;
    cout<<"****3.查看机房****"<<endl;
    cout<<"****4.清空预约****"<<endl;
    cout<<"****5.退出登录****"<<endl;
}

void ManagerController::showWindow() {
    while (true) {
        showOptions();
        int option;
        cin >> option;
        if (option == 1) {
            //查看所有预约
            vector<Order> orders= selectAllOrders();
            for(auto it=orders.begin();it!=orders.end();it++){
                cout<<(*it)<< endl;
            }

        } else if (option == 2) {
            //审核预约
            int orderId;
            string option;
            int state;
            cout<<"请输入订单ID"<<endl;
            cin>>orderId;
            Order* pOrder= selectOrderById(orderId);
            if(pOrder== nullptr){
                cout<<"当前预约不存在"<<endl;
            }else{
                cout<<*pOrder<<endl;
            }
            while (true) {
                cout << "请选择是否批准该预约 Y/N";
                cin>>option;
                if (option == "Y" || option == "N") {
                    state=option=="Y"?2:4;
                    break;
                }
            }
            if(auditOrder(orderId,state)){
                cout<<"审核完成！"<<endl;
            }else{
                cout<<"审核失败"<<endl;
            }


        } else if (option == 3) {
            cout<<"正在退出中"<<endl;
            return;
        } else {
            cout << Constants::ERROR_INPUT << endl;
        }
    }
}

ManagerController::ManagerController() {

}

ManagerController::ManagerController(Manager &m) {
    this->manager=manager;
}
